# ------------------ 系统初始化 开始 ------------------

import data as Data
import pgzrun
import tools as Tools
# import setting as Setting

WIDTH = Data.WIDTH
HEIGHT = Data.HEIGHT
screen = Tools.screen
Actor = Tools.Actor

# 为简化调用，部分常用角色在这里被提前实例化

HomePic = Actor('pic1',Tools.Central())
BackButton = Actor('left',[50,HEIGHT-50])
NextButoon = Actor('right',[WIDTH-50,HEIGHT-50])
# SettingButton = Actor('setting',[Tools.CentralX(),HEIGHT-50])

# ------------------ 系统初始化 结束 ------------------

# ------------------ 操作反馈部分 开始 ------------------

def SysWidgetDraw(): # 统一绘制系统级控件
    BackButton.draw()
    NextButoon.draw()
    # SettingButton.draw()

def SysWidgetTouch(pos): # 系统级控件触摸事件
    global nowPage
    if BackButton.collidepoint(pos):
        Tools.Debug(0,'BackButton')
        try:
            screen.clear()
            nowPage -= 1
            pages[nowPage].Enter()
        except: pass

    if NextButoon.collidepoint(pos):
        Tools.Debug(0,'NextButton')
        try:
            screen.clear()
            nowPage += 1
            pages[nowPage].Enter()
        except: pass
    
    # if SettingButton.collidepoint(pos):
        # Setting.Main()

def UserWidgetTouch(pos):# 用户级控件触摸事件
    try: pages[nowPage].Touch(pos)
    except: pass

def on_mouse_down(pos):
    SysWidgetTouch(pos) # 系统级控件触摸事件
    UserWidgetTouch(pos) # 用户级控件触摸事件

# ------------------ 操作反馈部分 结束 ------------------

# ------------------ 页面部分 开始 ------------------

pages = Data.pages
nowPage = Data.nowPage

# ------------------ 页面部分 结束 ------------------

# ------------------ 整体逻辑 开始 ------------------

def update():
    pages[nowPage].Update()
    SysWidgetDraw()

def on_mouse_down(pos):
    SysWidgetTouch(pos) # 系统级控件触摸事件
    UserWidgetTouch(pos) # 用户级控件触摸事件

pgzrun.go()

# ------------------ 整体逻辑 结束 ------------------